﻿using System;
using System.Collections.Generic;
using System.Linq;
using DomainModel;
using Repository.Abstract;
using Services.Abstract;

namespace Services.Concrete
{
    public class SubjectService : Service<Subject>, ISubjectService
    {
        private readonly ISubjectRepository _subjectRepository;

        public SubjectService(ISubjectRepository subjectRepository)
            : base(subjectRepository)
        {
            _subjectRepository = subjectRepository;
        }

        public Subject Get(string name)
        {
            if (name == null || string.IsNullOrEmpty(name))
                throw new ArgumentNullException("name");

            return _subjectRepository.GetByName(name);
        }

        public bool CanAddWorkType(Subject subject)
        {
            if (subject == null) 
                throw new ArgumentNullException("subject");

            var sum = subject.WorkTypes.Sum(workType => workType.BallsPersent);

            return sum < 100;
        }
    }
}